<?php

include '../Model/DAL/Connection.php';

$con = new Connection();
$conn = $con->configDB();
$strQuery = mysqli_query($conn, 'CALL GetBetInformationDaily()');
while ($row = mysqli_fetch_array($strQuery)) {
    $betNumber = $row['BetNumber'];
    $betDate = $row['BetDate'];
    $provinceID = $row['ProvinceID'];
    $subThreadRule = $row['SubThreadRuleID'];
    $betID = $row['BetID'];
    $betMoney = $row['BetMoney'];
    $winRateBet = $row['WinRateBet'];
    if ($row['RegionID'] == 'N') {
        switch ($subThreadRule) {
            case 'BL2SN' :
                mysqli_next_result($conn);
                $strQueryBL2SN = mysqli_query($conn, "CALL Score_N_BL2S('$betNumber','$betDate','$provinceID')");
                $rowBL2SN = mysqli_fetch_array($strQueryBL2SN);
                $total = $rowBL2SN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'BL3SN' :
                mysqli_next_result($conn);
                $strQueryBL3SN = mysqli_query($conn, "CALL Score_N_BL3S('$betNumber','$betDate','$provinceID')");
                $rowBL3SN = mysqli_fetch_array($strQueryBL3SN);
                $total = $rowBL3SN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'BL4SN' :
                mysqli_next_result($conn);
                $strQueryBL4SN = mysqli_query($conn, "CALL Score_N_BL4S('$betNumber','$betDate','$provinceID')");
                $rowBL4SN = mysqli_fetch_array($strQueryBL4SN);
                $total = $rowBL4SN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'DDDAN' :
                mysqli_next_result($conn);
                $strQueryDAN = mysqli_query($conn, "CALL Score_N_DA('$betNumber','$betDate','$provinceID')");
                $rowDAN = mysqli_fetch_array($strQueryDAN);
                $total = $rowDAN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'DDDUN' :
                mysqli_next_result($conn);
                $strQueryDUN = mysqli_query($conn, "CALL Score_N_DU('$betNumber','$betDate','$provinceID')");
                $rowDUN = mysqli_fetch_array($strQueryDUN);
                $total = $rowDUN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'LX2SN' :
                $arr = explode("-", $betNumber);
                $betNumber1 = $arr[0];
                $betNumber2 = $arr[1];
                mysqli_next_result($conn);
                $strQueryLX2SN = mysqli_query($conn, "CALL Score_N_LX2S('$betNumber1','$betNumber2','$betDate','$provinceID')");
                $rowLX2SN = mysqli_fetch_array($strQueryLX2SN);
                $total = 0;
                if ($rowLX2SN['total'] == 2)
                    $total = $rowLX2SN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'LX3SN' :
                $arr = explode("-", $betNumber);
                $betNumber1 = $arr[0];
                $betNumber2 = $arr[1];
                $betNumber3 = $arr[2];
                mysqli_next_result($conn);
                $strQueryLX3SN = mysqli_query($conn, "CALL Score_N_LX3S('$betNumber1','$betNumber2','$betNumber3','$betDate','$provinceID')");
                $rowLX3SN = mysqli_fetch_array($strQueryLX3SN);
                $total = 0;
                if ($rowLX2SN['total'] == 3)
                    $total = $rowLX3SN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'LX4SN' :
                $arr = explode("-", $betNumber);
                $betNumber1 = $arr[0];
                $betNumber2 = $arr[1];
                $betNumber3 = $arr[2];
                $betNumber4 = $arr[3];
                mysqli_next_result($conn);
                $strQueryLX4SN = mysqli_query($conn, "CALL Score_N_LX4S('$betNumber1','$betNumber2','$betNumber3','$betNumber4','$betDate','$provinceID')");
                $rowLX4SN = mysqli_fetch_array($strQueryLX4SN);
                $total = 0;
                if ($rowLX2SN['total'] == 4)
                    $total = $rowLX4SN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'SDDAN' :
                mysqli_next_result($conn);
                $strQuerySDDAN = mysqli_query($conn, "CALL Score_N_SDDA('$betNumber','$betDate','$provinceID')");
                $rowSDDAN = mysqli_fetch_array($strQuerySDDAN);
                $total = $rowSDDAN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'SDDBN' :
                mysqli_next_result($conn);
                $strQuerySDDBN = mysqli_query($conn, "CALL Score_N_SDDB('$betNumber','$betDate','$provinceID')");
                $rowSDDBN = mysqli_fetch_array($strQuerySDDBN);
                $total = $rowSDDBN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'XCDAN' :
                mysqli_next_result($conn);
                $strQueryXCDAN = mysqli_query($conn, "CALL Score_N_XCDA('$betNumber','$betDate','$provinceID')");
                $rowXCDAN = mysqli_fetch_array($strQueryXCDAN);
                $total = $rowXCDAN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'XCDDN' :
                mysqli_next_result($conn);
                $strQueryXCDDN = mysqli_query($conn, "CALL Score_N_XCDD('$betNumber','$betDate','$provinceID')");
                $rowXCDDN = mysqli_fetch_array($strQueryXCDDN);
                $total = $rowXCDDN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'XCDUN' :
                mysqli_next_result($conn);
                $strQueryXCDUN = mysqli_query($conn, "CALL Score_N_XCDU('$betNumber','$betDate','$provinceID')");
                $rowXCDUN = mysqli_fetch_array($strQueryXCDUN);
                $total = $rowXCDUN['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            default :
                break;
        }
    } else if ($row['RegionID'] == 'T') {
        switch ($subThreadRule) {
            case 'BL2ST' :
                mysqli_next_result($conn);
                $strQueryBL2ST = mysqli_query($conn, "CALL Score_T_BL2S('$betNumber','$betDate','$provinceID')");
                $rowBL2ST = mysqli_fetch_array($strQueryBL2ST);
                $total = $rowBL2ST['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'BL3ST' :
                mysqli_next_result($conn);
                $strQueryBL3ST = mysqli_query($conn, "CALL Score_T_BL3S('$betNumber','$betDate','$provinceID')");
                $rowBL3ST = mysqli_fetch_array($strQueryBL3ST);
                $total = $rowBL3ST['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'BL4ST' :
                mysqli_next_result($conn);
                $strQueryBL4ST = mysqli_query($conn, "CALL Score_T_BL4S('$betNumber','$betDate','$provinceID')");
                $rowBL4ST = mysqli_fetch_array($strQueryBL4ST);
                $total = $rowBL4ST['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'DDDAT' :
                mysqli_next_result($conn);
                $strQueryDAT = mysqli_query($conn, "CALL Score_T_DA('$betNumber','$betDate','$provinceID')");
                $rowDAT = mysqli_fetch_array($strQueryDAT);
                $total = $rowDAT['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'DDDUT' :
                mysqli_next_result($conn);
                $strQueryDUT = mysqli_query($conn, "CALL Score_T_DU('$betNumber','$betDate','$provinceID')");
                $rowDUT = mysqli_fetch_array($strQueryDUT);
                $total = $rowDUT['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'LX2ST' :
                $arr = explode("-", $betNumber);
                $betNumber1 = $arr[0];
                $betNumber2 = $arr[1];
                mysqli_next_result($conn);
                $strQueryLX2ST = mysqli_query($conn, "CALL Score_T_LX2S('$betNumber1','$betNumber2','$betDate','$provinceID')");
                $rowLX2ST = mysqli_fetch_array($strQueryLX2ST);
                $total = 0;
                if ($rowLX2SN['total'] == 2)
                    $total = $rowLX2ST['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'LX3ST' :
                $arr = explode("-", $betNumber);
                $betNumber1 = $arr[0];
                $betNumber2 = $arr[1];
                $betNumber3 = $arr[2];
                mysqli_next_result($conn);
                $strQueryLX3ST = mysqli_query($conn, "CALL Score_T_LX3S('$betNumber1','$betNumber2','$betNumber3','$betDate','$provinceID')");
                $rowLX3ST = mysqli_fetch_array($strQueryLX3ST);
                $total = 0;
                if ($rowLX2SN['total'] == 3)
                    $total = $rowLX3ST['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'LX4ST' :
                $arr = explode("-", $betNumber);
                $betNumber1 = $arr[0];
                $betNumber2 = $arr[1];
                $betNumber3 = $arr[2];
                $betNumber4 = $arr[3];
                mysqli_next_result($conn);
                $strQueryLX4ST = mysqli_query($conn, "CALL Score_T_LX4S('$betNumber1','$betNumber2','$betNumber3','$betNumber4','$betDate','$provinceID')");
                $rowLX4ST = mysqli_fetch_array($strQueryLX4ST);
                $total = 0;
                if ($rowLX2SN['total'] == 4)
                    $total = $rowLX4ST['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'SDDAT' :
                mysqli_next_result($conn);
                $strQuerySDDAT = mysqli_query($conn, "CALL Score_T_SDDA('$betNumber','$betDate','$provinceID')");
                $rowSDDAT = mysqli_fetch_array($strQuerySDDAT);
                $total = $rowSDDAT['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'SDDBT' :
                mysqli_next_result($conn);
                $strQuerySDDBT = mysqli_query($conn, "CALL Score_T_SDDB('$betNumber','$betDate','$provinceID')");
                $rowSDDBT = mysqli_fetch_array($strQuerySDDBT);
                $total = $rowSDDBT['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'XCDAT' :
                mysqli_next_result($conn);
                $strQueryXCDAT = mysqli_query($conn, "CALL Score_T_XCDA('$betNumber','$betDate','$provinceID')");
                $rowXCDAT = mysqli_fetch_array($strQueryXCDAT);
                $total = $rowXCDAT['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'XCDDT' :
                mysqli_next_result($conn);
                $strQueryXCDDT = mysqli_query($conn, "CALL Score_T_XCDD('$betNumber','$betDate','$provinceID')");
                $rowXCDDT = mysqli_fetch_array($strQueryXCDDT);
                $total = $rowXCDDT['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'XCDUT' :
                mysqli_next_result($conn);
                $strQueryXCDUT = mysqli_query($conn, "CALL Score_T_XCDU('$betNumber','$betDate','$provinceID')");
                $rowXCDUT = mysqli_fetch_array($strQueryXCDUT);
                $total = $rowXCDUT['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            default :
                break;
        }
    } else {
        switch ($subThreadRule) {
            case '3C3CB' :
                mysqli_next_result($conn);
                $strQuery3CB = mysqli_query($conn, "CALL Score_B_3C('$betNumber','$betDate','$provinceID')");
                $row3CB = mysqli_fetch_array($strQuery3CB);
                $total = $row3CB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'BL2SB' :
                mysqli_next_result($conn);
                $strQueryBL2SB = mysqli_query($conn, "CALL Score_B_BL2S('$betNumber','$betDate','$provinceID')");
                $rowBL2SB = mysqli_fetch_array($strQueryBL2SB);
                $total = $rowBL2SB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'BL3SB' :
                mysqli_next_result($conn);
                $strQueryBL3SB = mysqli_query($conn, "CALL Score_B_BL3S('$betNumber','$betDate','$provinceID')");
                $rowBL3SB = mysqli_fetch_array($strQueryBL3SB);
                $total = $rowBL3SB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'BL4SB' :
                mysqli_next_result($conn);
                $strQueryBL4SB = mysqli_query($conn, "CALL Score_B_BL4S('$betNumber','$betDate','$provinceID')");
                $rowBL4SB = mysqli_fetch_array($strQueryBL4SB);
                $total = $rowBL4SB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'DDDAB' :
                mysqli_next_result($conn);
                $strQueryDAB = mysqli_query($conn, "CALL Score_B_DA('$betNumber','$betDate','$provinceID')");
                $rowDAB = mysqli_fetch_array($strQueryDAB);
                $total = $rowDAB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'DDDUB' :
                mysqli_next_result($conn);
                $strQueryDUB = mysqli_query($conn, "CALL Score_B_DU('$betNumber','$betDate','$provinceID')");
                $rowDUB = mysqli_fetch_array($strQueryDUB);
                $total = $rowDUB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'LX2SB' :
                $arr = explode("-", $betNumber);
                $betNumber1 = $arr[0];
                $betNumber2 = $arr[1];
                mysqli_next_result($conn);
                $strQueryLX2SB = mysqli_query($conn, "CALL Score_B_LX2S('$betNumber1','$betNumber2','$betDate','$provinceID')");
                $rowLX2SB = mysqli_fetch_array($strQueryLX2SB);
                $total = 0;
                if ($rowLX2SN['total'] == 2)
                    $total = $rowLX2SB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'LX3SB' :
                $arr = explode("-", $betNumber);
                $betNumber1 = $arr[0];
                $betNumber2 = $arr[1];
                $betNumber3 = $arr[2];
                mysqli_next_result($conn);
                $strQueryLX3SB = mysqli_query($conn, "CALL Score_B_LX3S('$betNumber1','$betNumber2','$betNumber3','$betDate','$provinceID')");
                $rowLX3SB = mysqli_fetch_array($strQueryLX3SB);
                $total = 0;
                if ($rowLX2SN['total'] == 3)
                    $total = $rowLX3SB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'LX4SB' :
                $arr = explode("-", $betNumber);
                $betNumber1 = $arr[0];
                $betNumber2 = $arr[1];
                $betNumber3 = $arr[2];
                $betNumber4 = $arr[3];
                mysqli_next_result($conn);
                $strQueryLX4SB = mysqli_query($conn, "CALL Score_B_LX4S('$betNumber1','$betNumber2','$betNumber3','$betNumber4','$betDate','$provinceID')");
                $rowLX4SB = mysqli_fetch_array($strQueryLX4SB);
                $total = 0;
                if ($rowLX2SN['total'] == 4)
                    $total = $rowLX4SB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'SDDAB' :
                mysqli_next_result($conn);
                $strQuerySDDAB = mysqli_query($conn, "CALL Score_B_SDDA('$betNumber','$betDate','$provinceID')");
                $rowSDDAB = mysqli_fetch_array($strQuerySDDAB);
                $total = $rowSDDAB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            case 'SDDBB' :
                mysqli_next_result($conn);
                $strQuerySDDBB = mysqli_query($conn, "CALL Score_B_SDDB('$betNumber','$betDate','$provinceID')");
                $rowSDDBB = mysqli_fetch_array($strQuerySDDBB);
                $total = $rowSDDBB['total'];
                mysqli_next_result($conn);
                $strQueryResult = mysqli_query($conn, "CALL UpdateWhenHaveResult($betID,$total,'$betMoney','$winRateBet')");
                break;
            default :
                break;
        }
    }
}
?>